<?php
/*
* 入口文件
* 
* @author      wangcleer
* @version     1.0
* @time        2018.09.08
*
*/ 	
require_once('funtion.php');

// 获取数据库配置
$config = require('config.php');

// 判读配置 是否 填写完整
inspectConfig($config);

$dbConfig = $config['dbConfig'];

// 提醒期限
$days = $config['warnDays'];

$list = array();	

// 查询即将到期的数据

$sql = "select * from ***** where TO_DAYS(due_date) - TO_DAYS( NOW( ) )  between 0 and ".$days;

foreach ($dbConfig as $key => $value) {
	$mysqli = new mysqli($dbConfig[$key]['ip'], $dbConfig[$key]['username'], $dbConfig[$key]['password'], $dbConfig[$key]['db']);
	$mysqli->set_charset('utf8');
	$result = $mysqli->query($sql);
	if (!empty($result)) {
		while ($r = mysqli_fetch_assoc($result)) 
			{ 
				$r['server'] = $dbConfig[$key]['domain'];
				$list[]=$r; 
			}
	}
	$mysqli->close();
}


// 测试数据
// $list = array(
// 	array('server'=>'wechat','code'=>'code','name'=>'code_'),
// 	array('server'=>'qq','code'=>'code1','name'=>'code1_'),
// );


// 组合所有的结果

if(!empty($list)){

	$msg = '';
	
	// 发送提醒邮件

	$tpl = '<h3>你好,*****</h3>';
	
	foreach ($list as $key => $value) {
		$tpl .= "********************************************";
		$msg .= "********************************************";
	}
	
	$tpl .= '<p>*******************</p>';

	$info = sendMail($tpl,$config['mailConfig']);

	
	$msg .= '*******************';
	sendSms($config['phones'],$msg);
		
	// 记录日志
	setLog($info);
}else{
	setLog("No message today");
}


?>